import 'dart:async';

import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:provider/provider.dart';
import 'package:shopping_group/base/base_constant.dart';
import 'package:shopping_group/event/event.dart';
import 'package:shopping_group/main/lz_hot_cakes/model/lz_hot_cakes_play_video_model.dart';
import 'package:shopping_group/main/lz_hot_cakes/model/lz_hot_cakes_product_model.dart';
import 'package:shopping_group/main/lz_hot_cakes/provider/lz_hot_cakes_provider.dart';
import 'package:shopping_group/main/lz_hot_cakes/view_model/lz_hot_cakes_view_model.dart';
import 'package:shopping_group/main/lz_hot_cakes/widget/lz_hot_cakes_advert.dart';
import 'package:shopping_group/main/lz_hot_cakes/widget/lz_hot_cakes_product.dart';
import 'package:shopping_group/modle/more/bloc/more_bloc.dart';
import 'package:shopping_group/modle/more/bloc/video_bloc.dart';
import 'package:shopping_group/modle/more/entity/group_simple4fuli_entity.dart';
import 'package:shopping_group/modle/more/entity/group_simple_entity.dart';
import 'package:shopping_group/modle/more/ui/more_moneyjuan_page.dart';
import 'package:shopping_group/modle/more/ui/more_st_page.dart';
import 'package:shopping_group/modle/more/ui/video_fl_page.dart';
import 'package:shopping_group/modle/person/bloc/my_money_bloc.dart';
import 'package:shopping_group/modle/pingtuan/ui/pingtuan_complete_page.dart';
import 'package:shopping_group/modle/pingtuan/ui/pingtuan_do_page.dart';
import 'package:shopping_group/modle/pingtuan/ui/pingtuan_doing_page.dart';
import 'package:shopping_group/res/colors.dart';
import 'package:shopping_group/res/dimens.dart';
import 'package:shopping_group/utils/ad_video_util.dart';
import 'package:shopping_group/utils/object_util.dart';
import 'package:shopping_group/utils/route_util.dart';
import 'package:shopping_group/utils/widget_utils.dart';

class LzHotCakesPage extends StatefulWidget {
  @override
  _LzHotCakesPageState createState() => _LzHotCakesPageState();
}

class _LzHotCakesPageState extends State<LzHotCakesPage> with AutomaticKeepAliveClientMixin {
  MoreBloc _bloc;
  String _capitalAccount;
  StreamSubscription _colorSubscription;
  TextEditingController _controllerSreach = TextEditingController();
  List<GroupSimple4FuliEntity> _flList = [];
  List<GroupSimple4FuliEntity> _cjflList = [];

  List<String> _itmes = [];
  List<GroupSimpleEntity> _list = [];
  MyMoneyBloc _myMoneyBloc;
  StreamSubscription _resetMoneySubscription;
  StreamSubscription _loginSubscription;
  StreamSubscription _yzSubscription;
  StreamSubscription _refreshSubscription;
  StreamSubscription _videoCompletetSubscription;
  StreamSubscription _hideFlViewSubscription;
  StreamSubscription _hideFlclViewSubscription;
  VideoBloc _videoBloc;
  String _flDisplay = 'N';
  String _flclDisplay = 'N';
  @override
  void dispose() {
    _controllerSreach?.clear();
    _colorSubscription?.cancel();
    _resetMoneySubscription?.cancel();
    _loginSubscription?.cancel();
    _yzSubscription?.cancel();
    _refreshSubscription?.cancel();
    _videoCompletetSubscription?.cancel();
    _hideFlViewSubscription?.cancel();
    _hideFlclViewSubscription?.cancel();
    super.dispose();
  }

  @override
  void initState() {
    super.initState();
    _bloc = MoreBloc();
    _bloc.initDate.add(null);
    _myMoneyBloc = MyMoneyBloc();
    _bloc.initFlDate.add(null);
    _bloc.initFlcjDate.add(null);
    _videoBloc = VideoBloc();
    _capitalAccount = BaseConstant.capitalAccount;

    // HttpUtilAll.post(Apis.GUAN_GAOCT_INFO, data: {"val": "859153260399820800"}, headers: {'token': BaseConstant.token},
    //     success: (result) {
    //   print("result == ${result}");
    // }, error: (errorMsg) {
    //   BotToast.closeAllLoading();
    //   // 请求失败返回的错误信息
    //   BotToast.showText(text: errorMsg);
    // });

    // HttpUtilAll.post(Apis.AUC_COMMO_URL, data: {
    //   "val": "859153260399820800",
    //   "pageIndex": "1",
    //   "pageSize": "20",
    // }, headers: {
    //   'token': BaseConstant.token
    // }, success: (result) {
    //   print("result == ${result}");
    // }, error: (errorMsg) {
    //   BotToast.closeAllLoading();
    //   // 请求失败返回的错误信息
    //   BotToast.showText(text: errorMsg);
    // });

    _itmes
      ..add('https://lizhengyouxuan.oss-cn-shanghai.aliyuncs.com/lizhengyouxuan/pingtuan/pt_main1.png')
      ..add('https://lizhengyouxuan.oss-cn-shanghai.aliyuncs.com/lizhengyouxuan/pingtuan/pt_main2.png');

    // _flList
    //   ..add(GroupSimpleEntity()
    //     ..imgUrl =
    //         'https://lizhengyouxuan.oss-cn-shanghai.aliyuncs.com/lizhengyouxuan/group_business_img/group_50.png')
    //   ..add(GroupSimpleEntity()
    //     ..imgUrl =
    //         'https://lizhengyouxuan.oss-cn-shanghai.aliyuncs.com/lizhengyouxuan/group_business_img/group_100.png');

    _colorSubscription = eventBus.on<BlackEvent>().listen((event) {
      if (!mounted) {
        return;
      }
      setState(() {
        _capitalAccount = BaseConstant.capitalAccount;
      });
    });

    _resetMoneySubscription = eventBus.on<ResetMoneyEvent>().listen((event) {
      if (!mounted) {
        return;
      }
      if (BaseConstant.isLogin) {
        // _myMoneyBloc.initDate.add(null);
        LzHotCakesViewModel().initFuliVideoParma((model) {
          Provider.of<LzHotCakesProvider>(context, listen: false).setVideoModel(model);
        });
        //播放广告次数
        LzHotCakesViewModel().getUserLookGuanGaoCtInfo(context, (result) {
          Provider.of<LzHotCakesProvider>(context, listen: false).setGgHadDoCtMap(result);
        });
      }
    });

    _loginSubscription = eventBus.on<BlackForumEvent>().listen((event) {
      if (!mounted) {
        return;
      }
      //请求数据
      LzHotCakesViewModel().getHotCakes(context, (List<LzHotCakesProductModel> models) {
        Provider.of<LzHotCakesProvider>(context, listen: false).setDataList(models);
      });
      _bloc.initFlDate.add(null);
      _bloc.initFlcjDate.add(null);
    });
    _refreshSubscription = eventBus.on<RefreshFlEvent>().listen((event) {
      if (!mounted) {
        return;
      }
      _bloc.initFlDate.add(null);
      _bloc.initFlcjDate.add(null);

      LzHotCakesViewModel().initFuliVideoParma((model) {
        Provider.of<LzHotCakesProvider>(context, listen: false).setVideoModel(model);
      });
      //播放广告次数
      LzHotCakesViewModel().getUserLookGuanGaoCtInfo(context, (result) {
        Provider.of<LzHotCakesProvider>(context, listen: false).setGgHadDoCtMap(result);
      });
    });

    _yzSubscription = eventBus.on<StartFlVideoEvent>().listen((event) {
      if (!mounted) {
        return;
      }
      if (null != event) {
        GroupSimple4FuliEntity _groupEntity = event.entity;

        RouteUtil.goParameter(VideoFlPage(
            groupSpecId: event.groupSpecId,
            pushId: event.pushId,
            videoFileId: event.videoFileId,
            videoUrl: event.videoUrl,
            entity: event.entity));
      }
    });

    _videoCompletetSubscription = eventBus.on<AvFlCompleteEvent>().listen((event) {
      if (!mounted) {
        return;
      }

      Map<String, dynamic> data = {};
      data['groupSpecId'] = event.groupSpecId;
      data['pushId'] = event.pushId;
      data['videoFileId'] = event.videoFileId;
      data['userId'] = BaseConstant.userId;
      _videoBloc.initFlDate.add(data);

      //关闭视频的回调, 请求播放广告次数
      LzHotCakesViewModel().getUserLookGuanGaoCtInfo(context, (result) {
        Provider.of<LzHotCakesProvider>(context, listen: false).setGgHadDoCtMap(result);
      });

      LzHotCakesViewModel().initFuliVideoParma((model) {
        Provider.of<LzHotCakesProvider>(context, listen: false).playVideoModel = model;
      });
    });

    _hideFlViewSubscription = eventBus.on<HideFlEven>().listen((event) {
      if (!mounted) {
        return;
      }
      setState(() {
        _flDisplay = event.beDisplay;
      });
    });
    _hideFlclViewSubscription = eventBus.on<HideFlclEven>().listen((event) {
      if (!mounted) {
        return;
      }
      setState(() {
        _flclDisplay = event.beDisplay;
      });
    });

    WidgetsBinding.instance.addPostFrameCallback((_) {});
  }

  @override
  bool get wantKeepAlive => true;

  Widget _groupFlcjView(_flList) {
    return StreamBuilder(
      stream: _bloc.sendFlcjData,
      initialData: _cjflList,
      builder: (BuildContext contexts, AsyncSnapshot<Object> snapshot) {
        Object object = snapshot.data;
        if (object is List) {
          _cjflList = object;
        }
        return Container(
          margin: EdgeInsets.symmetric(horizontal: 8),
          color: Colours.title_white,
          child: Column(
            children: _getFlWidgetList(_cjflList),
          ),
        );
      },
    );
  }

  Widget _groupFlView(_flList) {
    return StreamBuilder(
      stream: _bloc.sendFlData,
      initialData: _flList,
      builder: (BuildContext contexts, AsyncSnapshot<Object> snapshot) {
        Object object = snapshot.data;
        if (object is List) {
          _flList = object;
        }
        return Container(
          margin: EdgeInsets.symmetric(horizontal: 8),
          color: Colours.title_white,
          child: Column(
            children: _getFlWidgetList(_flList),
          ),
        );
      },
    );
  }

  List<Widget> _getFlWidgetList(groupList) {
    List<Widget> list = [];
    int count = groupList.length;
    int endCount = count ~/ 2; //行数
    double taskCount = count / 2; //判断是否有多余
    List<GroupSimple4FuliEntity> taskEntity = [];
    for (var i = 0; i < count; i++) {
      if ((i + 1) % 2 == 0) {
        taskEntity.add(groupList[i]);
        list.add(Row(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: taskEntity.map((GroupSimple4FuliEntity entity) {
            return Expanded(
              child: getItemFlContainer(entity),
              flex: 1,
            ); //赋值后的Widget
          }).toList(),
        ));
        taskEntity = [];
      } else {
        taskEntity.add(groupList[i]);
      }
    }

    if (taskCount > endCount) {
      int length = list.length;
      int cout = 0;
      if (length < 2 && 0 != endCount) {
        cout = 2 - length;
      } else {
        cout = 2 - groupList.length;
      }
      for (var i = 0; i < cout; i++) {
        taskEntity.add(GroupSimple4FuliEntity()..name = '无');
      }
      list.add(Row(
        mainAxisAlignment: MainAxisAlignment.start,
        children: taskEntity.map((GroupSimple4FuliEntity entity) {
          return Expanded(
            child: getItemFlContainer(entity),
            flex: 1,
          );
        }).toList(),
      ));
    }
    return list;
  }

  Widget getItemFlContainer(GroupSimple4FuliEntity entity) {
    return GestureDetector(
      onTap: () {
        // if (!ObjectUtil.isEmptyString(entity.canJoin) &&
        //     'N' == entity.canJoin) {
        //   BotToast.showText(text: '无法参与活动');
        //   return;
        // }
        Map<String, dynamic> data = {};
        data['userId'] = BaseConstant.userId;
        data['groupSpecId'] = "GSF_ID_4_DS";
        data['pushId'] = '';
        data['videoFileId'] = '';
        data['entity'] = entity;
        _bloc.initValidateFlDate.add(data);
      },
      child: Container(
        margin: const EdgeInsets.symmetric(vertical: 8, horizontal: 8),
        alignment: Alignment.center,
        child: Material(
          borderRadius: BorderRadius.circular(4.0),
          color: Colours.title_white,
          // elevation: 5.0,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            children: <Widget>[
              Container(
                height: 110.0,
                width: 110.0,
                margin: const EdgeInsets.all(5.0),
                child: FadeInImage.assetNetwork(
                  image:
                      "https://lizhengyouxuan.oss-cn-shanghai.aliyuncs.com/lizhengyouxuan/group_business_img/20210829/manhe_5.png",
                  // ObjectUtil.isEmptyString(entity.canJoin)
                  //     ? entity.imgUrl
                  //     : ('Y' == entity.canJoin ? entity.imgUrl : entity.disabledImgUrl),
                  placeholder: 'images/picture_loading.png' /* 指定gif */,
                  fit: BoxFit.contain,
                ),
              ),
              Column(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  // Container(
                  //   margin: const EdgeInsets.only(left: 12, top: 12),
                  //   child: WidgetUtils.getTextMaxLinesView(
                  //       entity.name, Colours.text_2222, Dimens.FONT_SIZE_14,
                  //       overflow: TextOverflow.ellipsis),
                  // ),
                  // SizedBox(
                  //   height: 4,
                  // ),
                  Container(
                    margin: const EdgeInsets.only(left: 12, bottom: 10),
                    child: WidgetUtils.getTextColorView(
                        '须进行${entity.reBuySucCt}次，已进行${entity.pushCt}次', Colours.main_01, Dimens.FONT_SIZE_12,
                        textAlign: TextAlign.start, fontweight: FontWeight.w500),
                  ),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }

  String getCount(GroupSimple4FuliEntity entity) {
    if (ObjectUtil.isEmptyString(entity.pushCt)) {
      return '需进行${entity.reBuySucCt}次，进行0次';
      // } else if (entity.pushCt == entity.reBuySucCt) {
      //   return '已领取福利金';
    } else {
      return '需进行${entity.reBuySucCt}次，已进行${entity.pushCt}次';
    }
  }

  Widget _groupView(groupList) {
    return StreamBuilder(
      stream: _bloc.sendData,
      initialData: groupList,
      builder: (BuildContext contexts, AsyncSnapshot<Object> snapshot) {
        Object object = snapshot.data;
        if (object is List) {
          groupList = object;
        }
        return Container(
          margin: EdgeInsets.symmetric(horizontal: 8),
          color: Colours.title_white,
          child: Column(
            children: _getWidgetList(groupList),
          ),
        );
      },
    );
  }

  List<Widget> _getWidgetList(groupList) {
    List<Widget> list = [];
    int count = groupList.length;
    int endCount = count ~/ 2; //行数
    double taskCount = count / 2; //判断是否有多余
    List<GroupSimpleEntity> taskEntity = [];
    for (var i = 0; i < count; i++) {
      if ((i + 1) % 2 == 0) {
        taskEntity.add(groupList[i]);
        list.add(Row(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: taskEntity.map((GroupSimpleEntity entity) {
            return Expanded(
              child: getItemContainer(entity),
              flex: 1,
            ); //赋值后的Widget
          }).toList(),
        ));
        taskEntity = [];
      } else {
        taskEntity.add(groupList[i]);
      }
    }

    if (taskCount > endCount) {
      int length = list.length;
      int cout = 0;
      if (length < 2 && 0 != endCount) {
        cout = 2 - length;
      } else {
        cout = 2 - groupList.length;
      }
      for (var i = 0; i < cout; i++) {
        taskEntity.add(GroupSimpleEntity()..name = '无');
      }
      list.add(Row(
        mainAxisAlignment: MainAxisAlignment.start,
        children: taskEntity.map((GroupSimpleEntity entity) {
          return Expanded(
            child: getItemContainer(entity),
            flex: 1,
          );
        }).toList(),
      ));
    }
    return list;
  }

  Widget getItemContainer(GroupSimpleEntity entity) {
    return GestureDetector(
      onTap: () {
        if (ObjectUtil.isEmptyString(entity.groupSpecType)) {
          BotToast.showText(text: '功能暂未开放');
        } else {
          RouteUtil.goParameter(MoreStPage(
            title: _getType(entity),
            id: entity.groupSpecId,
          ));
        }
      },
      child: Container(
        margin: const EdgeInsets.symmetric(vertical: 8, horizontal: 8),
        alignment: Alignment.center,
        child: Material(
          borderRadius: BorderRadius.circular(4.0),
          color: Colours.title_white,
          // elevation: 5.0,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            children: <Widget>[
              Container(
                height: 110.0,
                width: 110.0,
                margin: const EdgeInsets.all(5.0),
                child: FadeInImage.assetNetwork(
                  image: entity.imgUrl,
                  placeholder: 'images/picture_loading.png' /* 指定gif */,
                  fit: BoxFit.contain,
                ),
              ),
              Column(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  // Container(
                  //   margin: const EdgeInsets.only(left: 12, top: 12),
                  //   child: WidgetUtils.getTextMaxLinesView(
                  //       entity.name, Colours.text_2222, Dimens.FONT_SIZE_14,
                  //       overflow: TextOverflow.ellipsis),
                  // ),
                  // SizedBox(
                  //   height: 4,
                  // ),
                  ObjectUtil.isEmptyString(entity.groupSpecType)
                      ? Container()
                      : Container(
                          margin: const EdgeInsets.only(left: 12, bottom: 10),
                          child: WidgetUtils.getTextColorView(
                              '${_getType(entity)}专区', Colours.main_01, Dimens.FONT_SIZE_16,
                              textAlign: TextAlign.start, fontweight: FontWeight.w500),
                        ),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }

  // Widget _groupView() {
  //   return StreamBuilder(
  //     stream: _bloc.sendData,
  //     initialData: _list,
  //     builder: (BuildContext contexts, AsyncSnapshot<Object> snapshot) {
  //       Object object = snapshot.data;
  //       if (object is List) {
  //         _list = object;
  //       }
  //       return Column(
  //         children: _list.map((GroupSimpleEntity entity) {
  //           return _pingtuanView(entity);
  //         }).toList(),
  //       );
  //     },
  //   );
  // }

  // Widget _pingtuanView(GroupSimpleEntity entity) {
  //   return GestureDetector(
  //     onTap: () {
  //       RouteUtil.goParameter(MoreStPage(
  //         title: _getType(entity),
  //         id: entity.groupSpecId,
  //       ));
  //     },
  //     child: Stack(
  //       children: <Widget>[
  //         WidgetUtils.buildNetworkImageView(entity.imgUrl,
  //             width: MediaQuery.of(context).size.width, height: 220),
  //         Container(
  //           padding: EdgeInsets.symmetric(vertical: 12, horizontal: 4),
  //           child: Column(
  //             children: <Widget>[
  //               Container(
  //                 padding: EdgeInsets.symmetric(horizontal: 8),
  //                 child: Row(
  //                   mainAxisAlignment: MainAxisAlignment.spaceBetween,
  //                   children: <Widget>[
  //                     WidgetUtils.showBoxBotton('${_getType(entity)}专区',
  //                         borderColor: Colours.title_white_80,
  //                         boxColor: Colours.title_white_80,
  //                         textColor: Colours.themeColor),
  //                     WidgetUtils.showBoxBotton('${entity.sucMenCt}人团',
  //                         borderColor: Colours.title_white_80,
  //                         boxColor: Colours.title_white_80,
  //                         textColor: Colours.themeColor),
  //                   ],
  //                 ),
  //               ),
  //               SizedBox(
  //                 height: 136,
  //               ),
  //               Container(
  //                 padding: EdgeInsets.symmetric(vertical: 8, horizontal: 12),
  //                 color: Colours.transparent_25,
  //                 child: Row(
  //                   mainAxisAlignment: MainAxisAlignment.spaceBetween,
  //                   children: <Widget>[
  //                     WidgetUtils.getTextColorView(
  //                         '当前正在推广', Colours.title_white, Dimens.FONT_SIZE_18),
  //                     WidgetUtils.getTextColorView(
  //                         '马上就成团了', Colours.title_white, Dimens.FONT_SIZE_18),
  //                   ],
  //                 ),
  //               ),
  //               Container(
  //                 padding: EdgeInsets.symmetric(vertical: 8, horizontal: 0),
  //                 color: Colours.title_white,
  //                 child: Row(
  //                   children: <Widget>[
  //                     Expanded(
  //                       child: Icon(
  //                         Icons.person,
  //                         color: Colours.themeColor,
  //                         size: 24,
  //                       ),
  //                       flex: 1,
  //                     ),
  //                     Expanded(
  //                       child: Icon(
  //                         Icons.person,
  //                         color: Colours.themeColor,
  //                         size: 24,
  //                       ),
  //                       flex: 1,
  //                     ),
  //                     Expanded(
  //                       child: Icon(
  //                         Icons.person,
  //                         color: Colours.themeColor,
  //                         size: 24,
  //                       ),
  //                       flex: 1,
  //                     ),
  //                     Expanded(
  //                       child: Icon(
  //                         Icons.person,
  //                         color: Colours.themeColor,
  //                         size: 24,
  //                       ),
  //                       flex: 1,
  //                     ),
  //                     Expanded(
  //                       child: Icon(
  //                         Icons.person,
  //                         color: Colours.themeColor,
  //                         size: 24,
  //                       ),
  //                       flex: 1,
  //                     ),
  //                     Expanded(
  //                       child: Icon(
  //                         Icons.person,
  //                         color: Colours.themeColor,
  //                         size: 24,
  //                       ),
  //                       flex: 1,
  //                     ),
  //                     Expanded(
  //                       child: Icon(
  //                         Icons.person,
  //                         color: Colours.themeColor,
  //                         size: 24,
  //                       ),
  //                       flex: 1,
  //                     ),
  //                     SizedBox(
  //                       width: 4,
  //                     ),
  //                     WidgetUtils.showBoxBotton('立即开团',
  //                         borderColor: Colours.themeColor,
  //                         boxColor: Colours.themeColor,
  //                         textColor: Colours.title_white),
  //                   ],
  //                 ),
  //               ),
  //             ],
  //           ),
  //         ),
  //       ],
  //     ),
  //   );
  // }

  String _getType(GroupSimpleEntity entity) {
    String type = '99';
    if (ObjectUtil.isEmptyString(entity.groupSpecType)) {
      return type;
    }

    List<String> list = entity.groupSpecType.split('_');
    if (ObjectUtil.isEmptyList(list) || 1 == list.length) {
      return type;
    }

    return list[1];
  }

  Widget _wushiDanView(title, content, colors) {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: Dimens.FONT_SIZE_8),
      decoration: BoxDecoration(
          border: Border.all(color: Colours.transparent, width: 0.0),
          borderRadius: BorderRadius.circular(10.0),
          color: colors),
      child: WidgetUtils.itmeStyleView(title, content,
          contentOverflow: TextOverflow.ellipsis,
          isExpanded: false,
          textColor: Colours.title_white,
          contentColor: Colours.title_white,
          titleFontweight: FontWeight.w500,
          contentMaxline: 2),
    );
  }

  Widget _xjjView() {
    return GestureDetector(
      onTap: () {},
      child: Container(
        margin: EdgeInsets.symmetric(horizontal: Dimens.FONT_SIZE_8),
        decoration: BoxDecoration(
            border: Border.all(color: Colours.transparent, width: 0.0),
            borderRadius: BorderRadius.circular(10.0),
            color: Colours.title_white),
        child: WidgetUtils.itmeStyleView('购买代理券', '余额:$_capitalAccount',
            contentOverflow: TextOverflow.ellipsis,
            isExpanded: true,
            contentAlignment: Alignment.centerRight,
            titleFontweight: FontWeight.w500,
            contentMaxline: 2, callBlack: () {
          RouteUtil.goParameter(MoreMoneyJuanPage(
            byYonJin: 'N',
          ));
        }),
      ),
    );
  }

  Widget _myOrder() {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: Dimens.FONT_SIZE_8),
      decoration: BoxDecoration(
          border: Border.all(color: Colours.transparent, width: 0.0),
          borderRadius: BorderRadius.circular(10.0),
          color: Colours.title_white),
      child: Container(
          decoration: new BoxDecoration(
            color: Colours.transparent,
          ),
          padding: const EdgeInsets.symmetric(vertical: 32),
          child: Flex(
            direction: Axis.horizontal,
            children: <Widget>[
              Expanded(
                flex: 1,
                child: GestureDetector(
                  onTap: () {
                    RouteUtil.goParameter(PingtuanDoPage());
                  },
                  child: Container(
                    color: Colors.transparent,
                    child: Column(
                      children: <Widget>[
                        Icon(
                          Icons.loyalty,
                          color: Colours.themeColor,
                          size: 32,
                        ),
                        Padding(
                          padding: const EdgeInsets.only(top: 8),
                          child: WidgetUtils.getTextColorView('推广中', Colours.text_2222, Dimens.FONT_SIZE_16),
                        ),
                      ],
                    ),
                  ),
                ),
              ),
              Expanded(
                flex: 1,
                child: GestureDetector(
                  onTap: () {
                    RouteUtil.goParameter(PingtuanDoingPage());
                  },
                  child: Container(
                      color: Colors.transparent,
                      child: Column(
                        children: <Widget>[
                          Icon(
                            Icons.layers,
                            color: Colours.themeColor,
                            size: 32,
                          ),
                          Padding(
                            padding: const EdgeInsets.only(top: 8),
                            child: WidgetUtils.getTextColorView('券已秒返', Colours.text_2222, Dimens.FONT_SIZE_16),
                          ),
                        ],
                      )),
                ),
              ),
              Expanded(
                flex: 1,
                child: GestureDetector(
                  onTap: () {
                    RouteUtil.goParameter(PingtuanCompletePage());
                  },
                  child: Container(
                      color: Colors.transparent,
                      child: Column(
                        children: <Widget>[
                          Icon(
                            Icons.shopping_basket,
                            color: Colours.themeColor,
                            size: 32,
                          ),
                          Padding(
                            padding: const EdgeInsets.only(top: 8),
                            child: WidgetUtils.getTextColorView('券已提交', Colours.text_2222, Dimens.FONT_SIZE_16),
                          ),
                        ],
                      )),
                ),
              ),
            ],
          )),
    );
  }

  Widget _noticeView() {
    return Container(
      margin: const EdgeInsets.only(top: 8, left: 8, right: 8),
      padding: const EdgeInsets.symmetric(horizontal: 16),
      decoration: BoxDecoration(
          border: Border.all(color: Colours.gray_f0, width: 1.0),
          borderRadius: BorderRadius.circular(30.0),
          color: Colours.title_white),
      child: Row(
        children: <Widget>[
          Padding(
            padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 8),
            child: WidgetUtils.buildNetworkImageView('https://static.jiujiupingou.com/Static/images/home_icon_xlb.png',
                width: 20, height: 20),
          ),
          SizedBox(
            width: 2,
          ),
          WidgetUtils.getTextColorView('每天开放时间', Colours.text_2222, Dimens.FONT_SIZE_16, fontweight: FontWeight.w500),
          SizedBox(
            width: 8,
          ),
          Expanded(
            child: WidgetUtils.marqueeWidget('07:08~23:08', scrollAxis: Axis.horizontal, fontSize: Dimens.FONT_SIZE_14),
          ),
        ],
      ),
    );
  }

  Widget _swiperView() {
    return Container(
        decoration: BoxDecoration(
            border: Border.all(color: Colours.gray_f0, width: 0),
            borderRadius: BorderRadius.circular(15.0),
            color: Colours.gray_f0),
        // padding: const EdgeInsets.only(top: 16, left: 16, right: 16),
        width: MediaQuery.of(context).size.width,
        height: 100.0,
        child: Swiper(
          itemBuilder: _swiperBuilderOne,
          itemCount: _itmes.length,
          pagination: SwiperPagination(
              builder: DotSwiperPaginationBuilder(
            color: Colors.black54,
            activeColor: Colours.gray_f0,
          )),
          //  control: SwiperControl(),
          scrollDirection: Axis.horizontal,
          autoplay: true,
          onTap: (index) {},
        ));
  }

  Widget _swiperBuilderOne(BuildContext context, int index) {
    return FadeInImage.assetNetwork(
      image: _itmes[index],
      placeholder: 'images/picture_loading.png',
      fit: BoxFit.fill,
    );
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Scaffold(
      resizeToAvoidBottomInset: false,
      backgroundColor: Color(0xFFF4F4F4),
      appBar: AppBar(
          elevation: 0.0,
          backgroundColor: Theme.of(context).primaryColor,
          title: WidgetUtils.getTextColorView("热销", Colors.white, Dimens.FONT_SIZE_20),
          centerTitle: true),
      body: Consumer<LzHotCakesProvider>(builder: (context, value, child) {
        return SingleChildScrollView(
          child: Column(
            children: <Widget>[
              Container(
                padding: EdgeInsets.fromLTRB(16, 16, 16, 16),
                child: Image.asset('images/icon_hot_cakes_1.png'),
              ),
              Container(
                padding: EdgeInsets.fromLTRB(16, 0, 16, 16),
                child: LzHotCakesAdvertWidget(),
              ),
              GestureDetector(
                onTap: () {
                  //播放广告视频

                  LzHotCakesPlayVideoModel playVideoModel =
                      Provider.of<LzHotCakesProvider>(context, listen: false)
                          .playVideoModel;

                  LzHotCakesViewModel().checkoutPlayVideo(playVideoModel,
                      (Map<String, dynamic> result) {
                    if (result.isEmpty) return;

                    RouteUtil.goParameter(VideoFlPage(
                        groupSpecId: playVideoModel.groupSpecId,
                        pushId: result["pushId"],
                        videoFileId: result["videoFileId"],
                        videoUrl: result["videoUrl"],
                        entity: playVideoModel));
                  });
                },
                child: Container(
                  padding: EdgeInsets.fromLTRB(16, 0, 16, 16),
                  child: Image.asset('images/icon_hot_cakes_2.png'),
                ),
              ),
              Container(
                  padding: EdgeInsets.fromLTRB(16, 0, 16, 0),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        "热销专区",
                        style: TextStyle(
                            color: Color(0xFF000000), fontSize: Dimens.FONT_SIZE_18, fontWeight: FontWeight.bold),
                      ),
                      Text(
                        "买热销得福利广告",
                        style: TextStyle(color: Color(0xFF878787), fontSize: Dimens.FONT_SIZE_10),
                      ),
                    ],
                  )),
              Container(
                child: ListView.builder(
                  shrinkWrap: true,
                  physics: new NeverScrollableScrollPhysics(),
                  scrollDirection: Axis.vertical,
                  itemBuilder: (context, index) {
                    return LzHotCakesProductWidget(cakesModel: value.dataList[index]);
                  },
                  itemCount: value.dataList.length,
                ),
              ),
            ],
          ),
        );
      }),

      // Container(
      //   height: double.infinity,
      //   decoration: new BoxDecoration(
      //     color: Colours.gray_f0,
      //   ),
      //   child: SingleChildScrollView(
      //     scrollDirection: Axis.vertical,
      //     reverse: false,
      //     padding: EdgeInsets.all(0.0),
      //     physics: BouncingScrollPhysics(),
      //     child: Column(
      //       children: <Widget>[
      //         // Image.asset('images/icon_mian_hot_cakes.png'),

      //         _swiperView(),
      //         // _noticeView(),

      //         Offstage(
      //           offstage: 'Y' == _flDisplay ? false : true,
      //           child: Column(
      //             children: <Widget>[
      //               SizedBox(
      //                 height: 4,
      //               ),
      //               _wushiDanView('品牌推广', ' ------福利专区', Colours.xuncha_wxc),
      //               SizedBox(
      //                 height: 8,
      //               ),
      //               _groupFlView(_flList),
      //             ],
      //           ),
      //         ),

      //         SizedBox(
      //           height: 8,
      //         ),
      //         _wushiDanView('品牌推广', ' ------代理任务专区', Colours.themeColor),
      //         SizedBox(
      //           height: 8,
      //         ),
      //         _xjjView(),
      //         SizedBox(
      //           height: 8,
      //         ),
      //         _groupView(_list),

      //         Offstage(
      //           offstage: 'Y' == _flclDisplay ? false : true,
      //           child: Column(
      //             children: <Widget>[
      //               SizedBox(
      //                 height: 8,
      //               ),
      //               _wushiDanView('品牌推广', ' ------现场福利专区', Colours.red_606),
      //               SizedBox(
      //                 height: 4,
      //               ),
      //               _groupFlcjView(_cjflList),
      //             ],
      //           ),
      //         ),
      //         SizedBox(
      //           height: 8,
      //         ),
      //         _myOrder(),
      //       ],
      //     ),
      //   ),
      // ),
    );
  }
}
